﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using BioCyber_Infection.Class;
using System.IO;

namespace BioCyber_Infection
{
    /// <summary>
    /// Esta classe serve para evitar a passagem de parâmetros comuns às demais classes.
    /// Graças a isso evitamos métodos como: Update(MouseState mouse, MouseState last_mouse, KeyboardState keyboard, ... )
    /// </summary>
    public static class Engine
    {

        #region Begin of Declaration

        /// <summary>
        /// Objetos que gerenciam o Mouse, Joystick e Keyboard
        /// </summary>
        public static KeyboardState keyboard, last_keyboard;
        public static MouseState mouse, last_mouse;
        public static GamePadState gamepad, last_gamepad;
        public static Rectangle mousePos;
        public static MemoryStream memoryStream = new MemoryStream();
        public static PacketReader packetReader = new PacketReader();
        public static PacketWriter packetWriter = new PacketWriter();
        #endregion

        #region Screens
        /// <summary>
        /// Screen's properties
        /// Declaração dos ENUMs das cenas
        /// </summary>
        public enum gameState { INTRO, MAINMENU, HISTORY, CREDITS, CREDITSSCREEN, SESSIONSCREEN, WAITROOM,GAMEOVER, THEEND, QUIT, LIVE, OPTIONS, STAGE1 };
        public static gameState currentState;
        #endregion

        /// <Is the Sprite1 coliding with Sprite2 ?>
        ///Checa se um sprite está colidindo com algum outro sprite 
        /// </summary>
        public static bool isColliding(Rectangle rec1, Rectangle rec2)
        {
            if (rec1.Intersects(rec2))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <Is the left/right button of mouse Pressed ?>
        /// Verifica se ocorreu um click no mouse
        /// </summary>
        /// <returns></returns>
        public static bool clicked()
        {
            if(mouse.LeftButton == ButtonState.Released && last_mouse.LeftButton == ButtonState.Pressed)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <Is the Joystick key OR any key of keyboard pressed ?>
        /// Verifica se alguma key OU algum Botão do Joystick foi pressionado
        /// </summary>
        /// <param name="key"></param>
        /// <param name="button"></param>
        /// <returns></returns>
        public static bool isPressed(Keys key, Buttons button)
        {
            return keyboard.IsKeyDown(key) || gamepad.IsButtonDown(button);
        }

        /// <summary>
        /// WTF?
        /// </summary>
        /// <param name="blahblahblah"></param>
        /// <param name="spriteBatch"></param>
        /// <param name="content"></param>
        public static void Trace(string blahblahblah,SpriteBatch spriteBatch,ContentManager content)
        {
            spriteBatch.DrawString(content.Load<SpriteFont>("SpriteFont1"), blahblahblah, Vector2.Zero, Color.White);
        }
    }
}
